import tkinter as tk
def click():
    text02.delete(0,"end")
    n = int(text01.get())
    t = 0
    s = ""
    while n > 0:
        a = n % 2
        n = n // 2
        t = t+a
        s = str(a)+s
    v = t % 2
    text02.insert(tk.END,s)
    lb04.config(text = 1-v)

 
win = tk.Tk()
win.title('奇校验')
win.geometry('240x180')
# 阻止Python GUI的大小调整
win.resizable(0, 0)
# 建组件
lb01 = tk.Label(win, text='待校验数:')
lb02 = tk.Label(win, text='二进制数:')
text01 = tk.Entry(win)
text02 = tk.Entry(win)
lb03 = tk.Label(win, text='校验位值:')
lb04 = tk.Label(win, text='')
btn = tk.Button(win, text='计算', command=click)   
# 布局
lb01.place(x=30, y=15)
lb02.place(x=30, y=60, )
text01.place(x=100, y=15, width=120, height=30)
text02.place(x=100, y=60, width=120, height=30)
lb03.place(x=30, y=100, )
lb04.place(x=100, y=100, )
btn.place(x=80, y=130, width=100, height=30)
# 接收窗体事件
win.mainloop()
